#pragma once
#include "RFLanDeviceNet.h"
#include "RFdeviceDefsNet.h"
#include "include\RF620Device.h"
#include "include\RFDeviceDefs.h"

using namespace RFDevice;
using namespace System;

namespace RFDeviceNet
{
	public ref class RF620DeviceNet : public RFLanDeviceNet
	{
	public:
		// Size of raw profile buffer in bytes
		static const size_t ProfileBufferSize = (2 + 2 + 4 * 1024);
		// Size of raw image buffer in bytes
		static const size_t ImageBufferSize = (512 * 640);
		// Number of items in single profile
		static const size_t ProfileValuesCount = (2 * 1024);
		
		static RF620DeviceNet^ CreateRF620Device();
		static RF620DeviceNet^ CreateRF620Device(_UDP_DEVINFOBLOCK_PC_Net^ devBlock);
		~RF620DeviceNet();

		bool Connect();
		bool Connect(_UDP_DEVINFOBLOCK_PC_Net^ devBlock );
		bool Disconnect();
		bool GetResult(array<byte>^% buffer);
		bool GetImage(array<byte>^% buffer);
		short GetResultInclinationAngle();
		bool ReadParams();
		bool WriteParams();
		bool FlushParams(bool bDefault);
		bool UDPConnect (USHORT UDPPort, String^ localIPAddress);
		bool UDPDisconnect();
		bool UDPGetResult(array<byte>^% buffer);
		bool PingTest();
		static UInt16 UDPPacketCounter(IntPtr buffer);

		//in, out, out
		USHORT ConvertResultToPoints(array<float>^ resultBuffer, array<DWORD>^% pointsBuffer, USHORT% count);
		//out, out
		USHORT GetNormalizedResult(array<DWORD>^% pointsBuffer, USHORT% count);
		//out, out
		USHORT UDPGetNormalizedResult(array<DWORD>^% pointsBuffer, USHORT% count);

		//in, out, out
		USHORT ConvertResultToPoints(array<USHORT>^ resultBuffer, array<float>^% pointsBuffer, USHORT% count);
		//out, out
		USHORT GetNormalizedResult(array<float>^% pointsBuffer, USHORT% count);
		//out, out
		USHORT UDPGetNormalizedResult(array<float>^% pointsBuffer, USHORT% count);

		DWORD GetSerialNumber();
		bool GetCapsExternalResultSync();
		bool GetCapsExternalMeasurementSync();
		bool GetCapsAnalogueOutputByCurrent();
		bool GetCapsAnalogueOutputByVoltage();
		bool GetCapsLaserModulation();
		WORD GetBaseDistance();
		WORD GetMeasurementRangeZ();
		WORD GetMeasurementRangeXSMR();
		WORD GetMeasurementRangeXEMR();
		DWORD GetFirmwareVersion();
		BYTE GetLaserLevel();
		WORD GetExposureTime();
		WORD GetSignalProcessingTime();
		BYTE GetLeftBoundary();
		BYTE GetWindowWidth();
		BYTE GetUpperBoundary();
		BYTE GetWindowHeight();
		bool GetExternalResultSyncEnabled();
		bool GetExternalResultSyncEdge();
		bool GetExternalMeasurementSyncEnabled();
		bool GetExternalMeasurementSyncEdge();
		bool GetAnalogueOutputSyncEnabled();
		bool GetAnalogueOutputSyncEdge();
		bool GetAnalogueOutputTTL_OUT0Level();
		BYTE GetExternalSignalDivisor();
		BYTE GetMeasurementDelay();
		BYTE GetAnalogueOutputNumberOfPoints();
		BYTE GetAnalogueOutputPointHoldupTime();
		array<Byte>^ GetDeviceIPAddress();
		array<Byte>^ GetHostIPAddress();
		array<Byte>^ GetNetworkMask();
		String^ GetHumanReadableDeviceIPAddress();
		String^ GetHumanReadableHostIPAddress();
		String^ GetHumanReadableNetworkMask();
		WORD GetHostPortNumber();
		BYTE GetUDPFrequency();
		short GetRotationAngle();
		bool SetLaserLevel(BYTE value);
		bool SetExposureTime(WORD value);
		bool SetSignalProcessingTime(WORD value);
		bool SetLeftBoundary(BYTE value);
		bool SetWindowWidth(BYTE value);
		bool SetUpperBoundary(BYTE value);
		bool SetWindowHeight(BYTE value);
		bool SetExternalResultSyncEnabled(bool value);
		bool SetExternalResultSyncEdge(bool value);
		bool SetExternalMeasurementSyncEnabled(bool value);
		bool SetExternalMeasurementSyncEdge(bool value);
		bool SetAnalogueOutputSyncEnabled(bool value);
		bool SetAnalogueOutputSyncEdge(bool value);
		bool SetAnalogueOutputTTL_OUT0Level(bool value);
		bool SetExternalSignalDivisor(BYTE value);

		bool SetMeasurementDelay(BYTE value);
		bool SetAnalogueOutputNumberOfPoints(BYTE value);
		bool SetAnalogueOutputPointHoldupTime(BYTE value);
		bool SetDeviceIPAddress(array<Byte>^ value);
		bool SetHostIPAddress(array<Byte>^ value);
		bool SetNetworkMask(array<Byte>^ value);
		bool SetHostPortNumber(WORD value);
		bool SetUDPFrequency(BYTE value);
		bool SetRotationAngle(short value);
		
		_UDP_DEVINFOBLOCK_PC_Net^ GetDevBlock();
		void CloneParameters(RF620DeviceNet^% dev);

	protected:
		RF620DeviceNet();
		RF620DeviceNet(RF620Device* device);
		RF620Device* _rf620Device;
	};
}

